package com.huixh.train.business.controller.admin;

import com.huixh.train.business.req.TrainStationQueryReq;
import com.huixh.train.business.req.TrainStationSaveReq;
import com.huixh.train.business.resp.TrainStationQueryResp;
import com.huixh.train.business.service.TrainStationService;
import com.huixh.train.common.resp.PageResult;
import com.huixh.train.common.resp.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author huixh
 */
@Validated
@RestController
@RequestMapping("/admin/trainStation")
@Tag(name = "车次车站管理", description = "车站管理")
public class TrainStationController {
    @Resource
    private TrainStationService trainStationService;

    @PostMapping("/save")
    @Operation(summary = "新增车站", method = "POST")
    public Result<?> save(@RequestBody @Valid TrainStationSaveReq trainStationSaveReq) {
        trainStationService.save(trainStationSaveReq);
        return Result.success();
    }

    @PostMapping("/quest-list")
    @Operation(summary = "查询车站列表", method = "POST")
    public PageResult<List<TrainStationQueryResp>> query(@RequestBody @Valid TrainStationQueryReq trainStationQueryReq) {
        return trainStationService.queryList(trainStationQueryReq);
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除车站", method = "DELETE")
    public Result<?> deleteById(@NotNull @PathVariable(name = "id") Long id) {
        trainStationService.delete(id);
        return Result.success("删除成功");
    }
}